
const connection = require('../app/database');

class userService {
    async create (user) {
        let { name, password } = user;
        
        //sql语句
        const statement = `INSERT INTO user (name, password) VALUES (?, ?);`;

        //插入数据库 execute
        const [ result ]= await connection.execute(statement, [name, password]);


        return result;
    }
    // 查询数据库用户
    async getUserByName (name) {
        const statement = `SELECT * FROM user WHERE name = ?;`;
        const [ result ] = await connection.execute(statement, [name]);
        // console.log(result)
        return result;
    }
}

module.exports = new userService();